using System;
using System.Collections.Generic;
using System.Linq;

namespace Kaleida.ServiceMonitor.Model.Runtime
{
    public class RoundRobinOperationOrder : OperationOrder
    {
        private int currentOperationIndex;

        public override T SelectItem<T>(IList<T> items)
        {
            if (!items.Any())
                throw new InvalidOperationException("Cannot select item. List has no items");

            currentOperationIndex = (currentOperationIndex < items.Count() - 1) ? currentOperationIndex + 1 : 0;
            return items[currentOperationIndex];
        }

        public override string Name
        {
            get { return "Round-Robin"; }
        }
    }
}